var mapOne=null;
var mapTwo=null;
var oldZoomOne=0;
var oldZoomTwo=0;
var enlargeCityIdOne = null;
var enlargeCityIdTwo = null;
var stationListOne = null;
var stationListTwo = null;

function nowDateFormat(dateString) {
	var arr1 = dateString.split(" ");
	var sdate = arr1[0].split('-');
	var result = sdate[0] + "年" + sdate[1] + "月" + sdate[2] + "日 " + arr1[1];
	return result;
}
function nowTimeFormat(dateString) {
	var arr1 = dateString.split(" ");
	var sdate = arr1[1].split(':');
	var result = sdate[0] + ":" + sdate[1];
	return result;
}


$(function(){
	mapOne = new BMap.Map("mapOne",{
		enableMapClick: false,
        minZoom : 5,
		maxZoom : 18
	});

	mapOne.centerAndZoom(new BMap.Point(106.236044, 36.14466), 5);
	//添加鼠标滚动缩放
	mapOne.enableScrollWheelZoom();
	//地图缩放
	mapOne.addEventListener("zoomend", function(){
		changeMapOneZoom(this.getZoom());
	});
	changeMapOneZoom(5);

	mapTwo = new BMap.Map("mapTwo",{
		enableMapClick: false,
		minZoom : 5,
		maxZoom : 18
	});
	mapTwo.centerAndZoom(new BMap.Point(106.236044, 36.14466), 5);
	//添加鼠标滚动缩放
	mapTwo.enableScrollWheelZoom();
	//地图缩放
	mapTwo.addEventListener("zoomend", function(){
		changeMapTwoZoom(this.getZoom());
	});
	changeMapTwoZoom(5);
});

//one
function ComplexCustomOverlayOne(point, text, cityId){
	this._point = point;
	this._text = text;
	this._cityId = cityId;
}
ComplexCustomOverlayOne.prototype = new BMap.Overlay();
ComplexCustomOverlayOne.prototype.initialize = function(mp){
	var ppoint=this._point;
	var cityId = this._cityId;
	this._map = mp;
	var div = this._div = document.createElement("div");
	div.style.position = "absolute";
	div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
	div.style.backgroundColor = "#EE5D5B";
	div.style.border = "1px solid #999";
	div.style.borderRadius= "50%";
	div.style.color = "#000";
	div.style.width = "30px";
	div.style.height = "30px";
	div.style.textAlign = "center";
	div.style.padding = "0px";
	div.style.lineHeight = "30px";
	div.style.whiteSpace = "nowrap";
	div.style.MozUserSelect = "none";
	div.style.fontSize = "14px"
	var span = this._span = document.createElement("span");
	div.appendChild(span);
	span.appendChild(document.createTextNode(this._text));

	var arrow = this._arrow = document.createElement("div");
	arrow.style.position = "absolute";
	arrow.style.width = "11px";
	arrow.style.height = "10px";
	arrow.style.top = "0";
	arrow.style.left = "20px";
	arrow.style.overflow = "hidden";
	div.appendChild(arrow);
	div.addEventListener("click",function(){
		enlargeCityIdOne = cityId;
		mapOne.setCenter(ppoint);
		mapOne.setZoom(oldZoomOne+3);
	});
	mapOne.getPanes().labelPane.appendChild(div);
	return div;
}
ComplexCustomOverlayOne.prototype.draw = function(){
	var map = this._map;
	var pixel = map.pointToOverlayPixel(this._point);
	this._div.style.left = pixel.x - parseInt(this._arrow.style.left) + "px";
	this._div.style.top  = pixel.y + "px";
}

function changeMapOneZoom(zoom){
	if(zoom<7){
		if(oldZoomOne==0||oldZoomOne>7){
			console.log("province");
			showProvinceOne();
		}
	}
	if(zoom>=7&&zoom<=10){
		if(oldZoomOne<7||oldZoomOne>10){
			console.log("city");
			showCityOne();
		}
	}
	if(zoom>10){
		if(oldZoomOne<=10){
			console.log("station");
			showAllStationsOne();
		}
	}
	oldZoomOne=zoom;
}

function showProvinceOne(){
	mapOne.clearOverlays();
	$.ajax({
		url : ctx+"/station/countByArea?type=province",
		data : {},
		dataType : 'json',
		type : 'get',
		success : function (data) {
			if(!showMsg(data)){
				return;
			}
			provinces=data.content;
			for(i=0;i<provinces.length;i++){
				var statistic=provinces[i];
				var myCompOverlay = new ComplexCustomOverlayOne(new BMap.Point(statistic.latitude,statistic.longitude), statistic.totalCount);
				mapOne.addOverlay(myCompOverlay);
			}
		}
	});
}
function showCityOne(){
	mapOne.clearOverlays();
	$.ajax({
		url : ctx+"/station/countByArea?type=city",
		data : {},
		dataType : 'json',
		type : 'get',
		success : function (data) {
			if(!showMsg(data)){
				return;
			}
			citys=data.content;
			for(i=0;i<citys.length;i++){
				var statistic=citys[i];
				var myCompOverlay = new ComplexCustomOverlayOne(new BMap.Point(statistic.latitude,statistic.longitude), statistic.totalCount, statistic.id);
				mapOne.addOverlay(myCompOverlay);
			}
		}
	});
}
function showAllStationsOne(){
	mapOne.clearOverlays();
	$.ajax({
		url : ctx+"/station/query",
		data : {},
		dataType : 'json',
		type : 'get',
		success : function (data) {
			if(!showMsg(data)){
				return;
			}
			stationListOne=data.content.content;
			for(i=0;i<stationListOne.length;i++){
				var station=stationListOne[i];
				if(enlargeCityIdOne!=null){
					if(station.cityId==enlargeCityIdOne){
						mapOne.setCenter(new BMap.Point(station.latitude, station.longitude));
						enlargeCityIdOne=null;
					}
				}
				addMarkerOne(station,i);
			}
		}
	});
}

function addMarkerOne(station,index){
	var marker = new BMap.Marker(new BMap.Point(station.latitude, station.longitude));
	var label = new BMap.Label(station.name, {offset: new BMap.Size(20, -10)});
	marker.setLabel(label);
	mapOne.addOverlay(marker);
	marker.setLabel(label);
	marker.addEventListener("click", function () {
		detailStationOne(index);
	});
	var id = station.id;
	var infoWindow;
	marker.addEventListener("mouseover", function () {
		var that=this;
		$.ajax({
			url: ctx + "/equipData/now?stationId=" + id,
			data: {},
			dataType: 'json',
			type: 'get',
			success: function (data) {
				if (data.result) {
					var content = data.content;
					var sContent="";
					if (content.collectionTime) {
						var imgUrl=ctx + "/images/web/no_img.png";
						var headPic=content.headPic;
						if(headPic) {
							var imgUrl = ctx + "/equipData/showFile?type=1&dataId=" + content.id;
						}
						sContent = '<div style="padding: 10px;"><table class="table-bordered base-table" style="width:320px;">' +
							'<tr><td class="base-title">车头照片：</td><td><img height="60" src="'+imgUrl+'"></td></tr>' +
							'<tr><td class="base-title">采集时间：</td><td>' + content.collectionTime + '</td></tr>' +
							'<tr><td class="base-title">车牌号码：</td><td>' + content.plateNo + '</td></tr>' +
							'<tr><td class="base-title">车轴数：</td><td>' + content.axleNumber + '</td></tr>' +
							'<tr><td class="base-title">车货总重：</td><td>' + content.totalWeight + '</td></tr>' +
							'<tr><td class="base-title">超限量：</td><td>' + content.overrunWeight + '%</td></tr>' +
							'</table></div>';
					}else{
						sContent = '<div style="padding: 10px;"><table class="table-bordered base-table" style="width:320px;">' +
							'<tr><td class="" style="text-align: center">无最近记录</td></tr>' +
							'</table></div>';
					}
					infoWindow = new BMap.InfoWindow(sContent);
					that.openInfoWindow(infoWindow);
				}
			}
		})
	});
	marker.addEventListener("mouseout", function () {
		this.closeInfoWindow(infoWindow);
	});
}

var selectedIdOne;
var ifFirstPageOne = true;
var showStationIdOne;
function detailStationOne(index) {
	selectedIdOne = null;
	var station = stationListOne[index];
	showStationIdOne=station.id;
	mapOne.centerAndZoom(new BMap.Point(station.latitude, station.longitude), 14);
	getBaseDataOne(station.id);
	getEquipDataOne(station.id);
	//initNowDataTimerOne();
	getNowDataOne(station.id);
	getHistoryDataOne(station.id, 0);
	$("#searchDivOne .search_detail").show();
	//$("#searchDivOne .search_detail").find(".panel").show();
}
function initNowDataTimerOne(){
	if(NowDataTimerOne!=null){
		window.clearInterval(NowDataTimerOne);
	}
	NowDataTimerOne = window.setInterval(function(){
		refreshNowDataOne();
	},60000);
}
function refreshNowDataOne(){
	getNowDataOne(showStationIdOne);
}
function getBaseDataOne(id) {
	$.ajax({
		url: ctx + "/station/detail",
		data: {id: id},
		dataType: 'json',
		type: 'get',
		success: function (data) {
			if (data.result) {
				var station = data.content;
				$("#baseCodeOne").html(station.code);
				$("#baseNameOne").html(station.name);
				$("#baseTypeOne").html(station.type);
				$("#baseDivisionOne").html(station.cityName + station.districtName);
				$("#baseOrganOne").html(station.organName);
				$("#baseAddressOne").html(station.address);
			}
		}
	})
}
function getEquipDataOne(id) {
	$("#equip-tbody-one").html("");
	$.ajax({
		url: ctx + "/equip/query?stationId=" + id,
		data: {id: id, size: 100},
		dataType: 'json',
		type: 'get',
		success: function (data) {
			if (data.result) {
				var equips = data.content.content;
				var txt = "";
				for (var i = 0; i < equips.length; i++) {
					var equip = equips[i];
					var type = equip.type;
					if (!type) {
						type = "";
					}
					var status = equip.status;
					if (!status) {
						status = "";
					}
					txt += '<tr><td>' + equip.code + '</td><td>' + equip.name + '</td><td>' + type + '</td><td>' + status + '</td></tr>';
				}
				$("#equip-tbody-one").html(txt);
			}
		}
	})
}
function getNowDataOne(id) {
	$("#countTimeOne").html("");
	$("#trainCountOne").html("");
	$("#now-tbody-one").html("");
	$.ajax({
		url: ctx + "/equipData/now?stationId=" + id,
		data: {},
		dataType: 'json',
		type: 'get',
		success: function (data) {
			if (data.result) {
				var content = data.content;
				var timeStr = content.countTime;
				var headPic = content.headPic;
				var timeShow = nowDateFormat(timeStr);

				$("#countTimeOne").html(timeShow);
				$("#trainCountOne").html(content.trainCount);
				if (content.collectionTime == null) {
					$("#now-tbody-one").html("<tr><td colspan='5'>暂无数据</td></tr>");
					$(".now-img-td-one").hide();
				} else {
					var time = nowTimeFormat(content.collectionTime);
					$(".now-img-td-one").show();
					var imgUrl=ctx + "/images/web/no_img.png";
					if(headPic) {
						var imgUrl = ctx + "/equipData/showFile?type=1&dataId=" + content.id;
					}
					$(document).find(".headpicOne").attr("src",imgUrl);
					$("#now-tbody-one").html("<tr><td>" + content.collectionTime + "</td><td>" + content.plateNo + "</td><td>" + content.axleNumber + "</td><td>" + content.totalWeight + "</td><td>" + content.overrunWeight * 100 + "%</td></tr>");
				}
			}
		}
	})
}
function getHistoryDataOne(id, page) {
	$("#history-tbody-one").html("");
	$.ajax({
		url: ctx + "/equipData/query?stationId=" + id,
		data: {page: page, size: 10},
		dataType: 'json',
		type: 'get',
		success: function (data) {
			if (data.result) {
				var num = data.content.totalPages;
				if (selectedIdOne != id) {
					ifFirstPageOne = true;
					$("#PaginationOne").pagination(num, {
						num_edge_entries: 1, //边缘页数
						num_display_entries: 4, //主体页数
						callback: pageselectCallbackOne,
						items_per_page: 1, //每页显示1项
						prev_text: "前一页",
						next_text: "后一页"
					});
				}
				selectedIdOne = id;
				var histories = data.content.content;
				initHistoryDataOne(histories);
			}
		}
	})
}
function pageselectCallbackOne(page_index, jq) {
	if (!ifFirstPageOne) {
		getHistoryDataOne(selectedIdOne, page_index);
	}
	ifFirstPageOne = false;
	return true;
}
function initHistoryDataOne(histories) {
	if (histories == null || histories.length == 0) {
		$("#history-tbody-one").html("<tr><td colspan='5'>暂无数据</td></tr>");
	} else {
		var txt = "";
		for (var i = 0; i < histories.length; i++) {
			var history = histories[i];
			var time = nowTimeFormat(history.collectionTime);
			var plateNo = history.plateNo;
			if (!plateNo) {
				plateNo = "";
			}
			var axleNumber = history.axleNumber;
			if (!axleNumber) {
				axleNumber = "";
			}
			var totalWeight = history.totalWeight;
			if (!totalWeight) {
				totalWeight = "";
			}
			var overrunWeight = history.overrunWeight;
			if (!overrunWeight) {
				overrunWeight = "";
			} else {
				overrunWeight = overrunWeight * 100 + "%";
			}
			txt += "<tr><td>" + history.collectionTime + "</td><td>" + plateNo + "</td><td>" + axleNumber + "</td><td>" + totalWeight + "</td><td>" + overrunWeight + "</td></tr>";
		}
		$("#history-tbody-one").html(txt);
	}
}







//two
function ComplexCustomOverlayTwo(point, text, cityId){
	this._point = point;
	this._text = text;
	this._cityId = cityId;
}
ComplexCustomOverlayTwo.prototype = new BMap.Overlay();
ComplexCustomOverlayTwo.prototype.initialize = function(mp){
	var ppoint=this._point;
	var cityId = this._cityId;
	this._map = mp;
	var div = this._div = document.createElement("div");
	div.style.position = "absolute";
	div.style.zIndex = BMap.Overlay.getZIndex(this._point.lat);
	div.style.backgroundColor = "#EE5D5B";
	div.style.border = "1px solid #999";
	div.style.borderRadius= "50%";
	div.style.color = "#000";
	div.style.width = "30px";
	div.style.height = "30px";
	div.style.textAlign = "center";
	div.style.padding = "0px";
	div.style.lineHeight = "30px";
	div.style.whiteSpace = "nowrap";
	div.style.MozUserSelect = "none";
	div.style.fontSize = "14px"
	var span = this._span = document.createElement("span");
	div.appendChild(span);
	span.appendChild(document.createTextNode(this._text));

	var arrow = this._arrow = document.createElement("div");
	arrow.style.position = "absolute";
	arrow.style.width = "11px";
	arrow.style.height = "10px";
	arrow.style.top = "0";
	arrow.style.left = "20px";
	arrow.style.overflow = "hidden";
	div.appendChild(arrow);
	div.addEventListener("click",function(){
		enlargeCityIdTwo = cityId;
		mapTwo.setCenter(ppoint);
		mapTwo.setZoom(oldZoomTwo+3);
	});
	mapTwo.getPanes().labelPane.appendChild(div);
	return div;
}
ComplexCustomOverlayTwo.prototype.draw = function(){
	var map = this._map;
	var pixel = map.pointToOverlayPixel(this._point);
	this._div.style.left = pixel.x - parseInt(this._arrow.style.left) + "px";
	this._div.style.top  = pixel.y + "px";
}

function changeMapTwoZoom(zoom){
	if(zoom<7){
		if(oldZoomTwo==0||oldZoomTwo>7){
			showProvinceTwo();
		}
	}
	if(zoom>=7&&zoom<=10){
		if(oldZoomTwo<7||oldZoomTwo>10){
			showCityTwo();
		}
	}
	if(zoom>10){
		if(oldZoomTwo<=10){
			showAllStationsTwo();
		}
	}
	oldZoomTwo=zoom;
}

function showProvinceTwo(){
	mapTwo.clearOverlays();
	$.ajax({
		url : ctx+"/station/countByArea?type=province",
		data : {},
		dataType : 'json',
		type : 'get',
		success : function (data) {
			if(!showMsg(data)){
				return;
			}
			provinces=data.content;
			for(i=0;i<provinces.length;i++){
				var statistic=provinces[i];
				var myCompOverlay = new ComplexCustomOverlayTwo(new BMap.Point(statistic.latitude,statistic.longitude), statistic.totalCount);
				mapTwo.addOverlay(myCompOverlay);
			}
		}
	});
}
function showCityTwo(){
	mapTwo.clearOverlays();
	$.ajax({
		url : ctx+"/station/countByArea?type=city",
		data : {},
		dataType : 'json',
		type : 'get',
		success : function (data) {
			if(!showMsg(data)){
				return;
			}
			citys=data.content;
			for(i=0;i<citys.length;i++){
				var statistic=citys[i];
				var myCompOverlay = new ComplexCustomOverlayTwo(new BMap.Point(statistic.latitude,statistic.longitude), statistic.totalCount, statistic.id);
				mapTwo.addOverlay(myCompOverlay);
			}
		}
	});
}
function showAllStationsTwo(){
	mapTwo.clearOverlays();
	$.ajax({
		url : ctx+"/station/query",
		data : {},
		dataType : 'json',
		type : 'get',
		success : function (data) {
			if(!showMsg(data)){
				return;
			}
			stationListTwo=data.content.content;
			for(i=0;i<stationListTwo.length;i++){
				var station=stationListTwo[i];
				if(enlargeCityIdTwo!=null){
					if(station.cityId==enlargeCityIdTwo){
						mapTwo.setCenter(new BMap.Point(station.latitude, station.longitude));
						enlargeCityIdTwo=null;
					}
				}
				addMarkerTwo(station,i);
			}
		}
	});
}

function addMarkerTwo(station,index){
	var marker = new BMap.Marker(new BMap.Point(station.latitude, station.longitude));
	var label = new BMap.Label(station.name, {offset: new BMap.Size(20, -10)});
	marker.setLabel(label);
	mapTwo.addOverlay(marker);
	marker.setLabel(label);
	marker.addEventListener("click", function () {
		detailStationTwo(index);
	});
	var id = station.id;
	var infoWindow;
	marker.addEventListener("mouseover", function () {
		var that=this;
		$.ajax({
			url: ctx + "/equipData/now?stationId=" + id,
			data: {},
			dataType: 'json',
			type: 'get',
			success: function (data) {
				if (data.result) {
					var content = data.content;
					var sContent="";
					if (content.collectionTime) {
						var imgUrl=ctx + "/images/web/no_img.png";
						var headPic=content.headPic;
						if(headPic) {
							var imgUrl = ctx + "/equipData/showFile?type=1&dataId=" + content.id;
						}
						sContent = '<div style="padding: 10px;"><table class="table-bordered base-table" style="width:320px;">' +
							'<tr><td class="base-title">车头照片：</td><td><img height="60" src="'+imgUrl+'"></td></tr>' +
							'<tr><td class="base-title">采集时间：</td><td>' + content.collectionTime + '</td></tr>' +
							'<tr><td class="base-title">车牌号码：</td><td>' + content.plateNo + '</td></tr>' +
							'<tr><td class="base-title">车轴数：</td><td>' + content.axleNumber + '</td></tr>' +
							'<tr><td class="base-title">车货总重：</td><td>' + content.totalWeight + '</td></tr>' +
							'<tr><td class="base-title">超限量：</td><td>' + content.overrunWeight + '%</td></tr>' +
							'</table></div>';
					}else{
						sContent = '<div style="padding: 10px;"><table class="table-bordered base-table" style="width:320px;">' +
							'<tr><td class="" style="text-align: center">无最近记录</td></tr>' +
							'</table></div>';
					}
					infoWindow = new BMap.InfoWindow(sContent);
					that.openInfoWindow(infoWindow);
				}
			}
		})
	});
	marker.addEventListener("mouseout", function () {
		this.closeInfoWindow(infoWindow);
	});
}

var selectedIdTwo;
var ifFirstPageTwo = true;
var showStationIdTwo;
function detailStationTwo(index) {
	selectedIdTwo = null;
	var station = stationListTwo[index];
	showStationIdTwo=station.id;
	mapTwo.centerAndZoom(new BMap.Point(station.latitude, station.longitude), 14);
	getBaseDataTwo(station.id);
	getEquipDataTwo(station.id);
	getNowDataTwo(station.id);
	//initNowDataTimerTwo();
	getHistoryDataTwo(station.id, 0);
	$("#searchDivTwo .search_detail").show();
	//$("#searchDivTwo .search_detail").find(".panel").show();
}
function initNowDataTimerTwo(){
	if(NowDataTimerTwo!=null){
		window.clearInterval(NowDataTimerTwo);
	}
	NowDataTimerTwo = window.setInterval(function(){
		refreshNowDataTwo();
	},60000);
}
function refreshNowDataTwo(){
	getNowDataTwo(showStationIdTwo);
}
function getBaseDataTwo(id) {
	$.ajax({
		url: ctx + "/station/detail",
		data: {id: id},
		dataType: 'json',
		type: 'get',
		success: function (data) {
			if (data.result) {
				var station = data.content;
				$("#baseCodeTwo").html(station.code);
				$("#baseNameTwo").html(station.name);
				$("#baseTypeTwo").html(station.type);
				$("#baseDivisionTwo").html(station.cityName + station.districtName);
				$("#baseOrganTwo").html(station.organName);
				$("#baseAddressTwo").html(station.address);
			}
		}
	})
}
function getEquipDataTwo(id) {
	$("#equip-tbody-two").html("");
	$.ajax({
		url: ctx + "/equip/query?stationId=" + id,
		data: {id: id, size: 100},
		dataType: 'json',
		type: 'get',
		success: function (data) {
			if (data.result) {
				var equips = data.content.content;
				var txt = "";
				for (var i = 0; i < equips.length; i++) {
					var equip = equips[i];
					var type = equip.type;
					if (!type) {
						type = "";
					}
					var status = equip.status;
					if (!status) {
						status = "";
					}
					txt += '<tr><td>' + equip.code + '</td><td>' + equip.name + '</td><td>' + type + '</td><td>' + status + '</td></tr>';
				}
				$("#equip-tbody-two").html(txt);
			}
		}
	})
}
function getNowDataTwo(id) {
	$("#countTimeTwo").html("");
	$("#trainCountTwo").html("");
	$("#now-tbody-two").html("");
	$.ajax({
		url: ctx + "/equipData/now?stationId=" + id,
		data: {},
		dataType: 'json',
		type: 'get',
		success: function (data) {
			if (data.result) {
				var content = data.content;
				var timeStr = content.countTime;
				var headPic = content.headPic;
				var timeShow = nowDateFormat(timeStr);

				$("#countTimeTwo").html(timeShow);
				$("#trainCountTwo").html(content.trainCount);
				if (content.collectionTime == null) {
					$("#now-tbody-two").html("<tr><td colspan='5'>暂无数据</td></tr>");
					$(".now-img-td-two").hide();
				} else {
					var time = nowTimeFormat(content.collectionTime);
					$(".now-img-td-two").show();
					var imgUrl=ctx + "/images/web/no_img.png";
					if(headPic) {
						var imgUrl = ctx + "/equipData/showFile?type=1&dataId=" + content.id;
					}
					$(document).find(".headpicTwo").attr("src",imgUrl);
					$("#now-tbody-two").html("<tr><td>" + content.collectionTime + "</td><td>" + content.plateNo + "</td><td>" + content.axleNumber + "</td><td>" + content.totalWeight + "</td><td>" + content.overrunWeight * 100 + "%</td></tr>");
				}
			}
		}
	})
}
function getHistoryDataTwo(id, page) {
	$("#history-tbody-two").html("");
	$.ajax({
		url: ctx + "/equipData/query?stationId=" + id,
		data: {page: page, size: 10},
		dataType: 'json',
		type: 'get',
		success: function (data) {
			if (data.result) {
				var num = data.content.totalPages;
				if (selectedIdTwo != id) {
					ifFirstPageTwo = true;
					$("#PaginationTwo").pagination(num, {
						num_edge_entries: 1, //边缘页数
						num_display_entries: 4, //主体页数
						callback: pageselectCallbackTwo,
						items_per_page: 1, //每页显示1项
						prev_text: "前一页",
						next_text: "后一页"
					});
				}
				selectedIdTwo = id;
				var histories = data.content.content;
				initHistoryDataTwo(histories);
			}
		}
	})
}
function pageselectCallbackTwo(page_index, jq) {
	if (!ifFirstPageTwo) {
		getHistoryDataTwo(selectedIdTwo, page_index);
	}
	ifFirstPageTwo = false;
	return true;
}
function initHistoryDataTwo(histories) {
	if (histories == null || histories.length == 0) {
		$("#history-tbody-two").html("<tr><td colspan='5'>暂无数据</td></tr>");
	} else {
		var txt = "";
		for (var i = 0; i < histories.length; i++) {
			var history = histories[i];
			var time = nowTimeFormat(history.collectionTime);
			var plateNo = history.plateNo;
			if (!plateNo) {
				plateNo = "";
			}
			var axleNumber = history.axleNumber;
			if (!axleNumber) {
				axleNumber = "";
			}
			var totalWeight = history.totalWeight;
			if (!totalWeight) {
				totalWeight = "";
			}
			var overrunWeight = history.overrunWeight;
			if (!overrunWeight) {
				overrunWeight = "";
			} else {
				overrunWeight = overrunWeight * 100 + "%";
			}
			txt += "<tr><td>" + history.collectionTime + "</td><td>" + plateNo + "</td><td>" + axleNumber + "</td><td>" + totalWeight + "</td><td>" + overrunWeight + "</td></tr>";
		}
		$("#history-tbody-two").html(txt);
	}
}


$(document).ready(function(){

	//cleanNowDataTimer();
	$('.search_detail .easyui-panel').panel({
		onBeforeClose: function () {
			$(".search_detail").hide();
			return false;
		}
	});
	$(document).on('click', '.initChoose', function () {
		initChoose($(this));
	});
	getBaseCountData();
});

function chooseCityOne(cityId){
	$.ajax({
		url: ctx + "/station/countByArea?type=city&areaId="+cityId,
		data: {},
		dataType: 'json',
		type: 'get',
		success: function (data) {
			if (data.result) {
				var content = data.content[0];
				var text="站点："+content.totalCount+","+"治超站："+content.typeCount1+","+"收费站："+content.typeCount2+","
					+"移动执法："+content.typeCount3+","+"源头企业："+content.typeCount4+","+"流动执法："+content.typeCount5;
				$("#cityFilterOne").find(".city-count").html(text);
				mapOne.setCenter(new BMap.Point(content.latitude,content.longitude));
				mapOne.setZoom(9);
			}
		}
	})
}
function chooseCityTwo(cityId){
	$.ajax({
		url: ctx + "/station/countByArea?type=city&areaId="+cityId,
		data: {},
		dataType: 'json',
		type: 'get',
		success: function (data) {
			if (data.result) {
				var content = data.content[0];
				var text="站点："+content.totalCount+","+"治超站："+content.typeCount1+","+"收费站："+content.typeCount2+","
					+"移动执法："+content.typeCount3+","+"源头企业："+content.typeCount4+","+"流动执法："+content.typeCount5;
				$("#cityFilterTwo").find(".city-count").html(text);
				mapTwo.setCenter(new BMap.Point(content.latitude,content.longitude));
				mapTwo.setZoom(9);
			}
		}
	})
}

function getBaseCountData(){
	$.ajax({
		url: ctx + "/station/countByArea?type=city&areaId=0",
		data: {},
		dataType: 'json',
		type: 'get',
		success: function (data) {
			if (data.result) {
				var content = data.content[0];
				var text="站点："+content.totalCount+","+"治超站："+content.typeCount1+","+"收费站："+content.typeCount2+","
				+"移动执法："+content.typeCount3+","+"源头企业："+content.typeCount4+","+"流动执法："+content.typeCount5;
				$(document).find(".city-count").html(text);
			}
		}
	})
}